import Vue from 'vue'
import Vuex from 'vuex'
import user from './user/index'
import movie from './movie/movie'
import home from "./home/home";
import music from "./music/music"
import audioMusic from "./music/Player";
Vue.use(Vuex)

var checkEmail=(rule,value,callback)=>{
  const reg=/^\w+@\w+(\.\w+)+$/
  if(reg.test(value)){
    callback();
  }else {return callback(new Error('请输入合法的邮箱'))}
}
var checkMoblie=(rule,value,callback)=>{
  const reg= /^1[34578]\d{9}$/
  if(reg.test(value)){
    callback();
  }else {return callback(new Error('请输入合法的手机号'))}
}

export default new Vuex.Store({
  state: {
    UserRules:{
      username:[{ required: true, message: '请输入用户名', trigger: 'blur' },
        { min:3, max:5,message:'长度在 3 到 5 个字符', trigger:'blur' }
      ],
      password: [
        { required: true, message: '请输入密码', trigger: 'blur' }
      ],
      checkPass: [
      ],
      email:[{required:true,message:'请输入邮箱',trigger:'blur'},{
        validator:checkEmail,message: '邮箱格式不正确，请重新输入',trigger: 'blur'
      }],
      mobile: [{required:true,message:'请输入手机号',trigger:'blur'},
        {validator:checkMoblie,trigger: 'blur'}]
    }
  },
  getters:{

  },
  mutations: {
checkpass(state,playload){
  function validatePass2(rule, value, callback){
    if (value === '') {
      callback(new Error('请再次输入密码'));
    } else if (value !== playload.password) {
      callback(new Error('两次输入密码不一致!'));
    } else {
      callback();
    }}
  state.UserRules.checkPass=[{required: true, validator: validatePass2, trigger: 'blur'}]
}
  },
  actions:{
  },
  modules:{
    user,
    movie,
    home,
    music,
    audioMusic,
  }
})

